class Requirement < ActiveRecord::Base
  belongs_to :user
  belongs_to :project

  has_many :taggings, :as => :taggable
  has_many :tags, :through => :taggings

  state_machine :state, :initial => :assigned do
    event :assign do
      transition :submitted => :assigned
    end

    event :working do
      transition [:assigned, :reopen] => :resolved, :resolved => :finished
    end

    event :hang_up do
      transition [:submitted, :reopen] => :suspend
    end

    event :rework do
      transition [:finished, :resolved, :suspend] => :reopen
    end
  end

  def self.count_unfinished_requirements
    count(:all, :conditions => ["state NOT IN (?)", ["resolved", "finished"]]).to_s
  end

  def self.unfinished_requirements
    all(:conditions => ["state NOT IN (?)", ["resolved", "finished"]])
  end

end
